package com.briup.bms.service.impl;

import com.briup.bms.bean.SItem;
import com.briup.bms.common.utils.BeanUtils.ColaBeanUtils;
import com.briup.bms.dao.SItemMapper;
import com.briup.bms.dao.SProductMapper;
import com.briup.bms.service.SItemService;
import com.briup.bms.web.vm.ItemVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Paocha
 * @date: 2021-11-25-16:34
 */
@Service
public class SItemServiceImpl implements SItemService {

    private SItemMapper itemMapper;
    private SProductMapper productMapper;


    public SItemServiceImpl(SItemMapper itemMapper, SProductMapper productMapper) {
        this.itemMapper = itemMapper;
        this.productMapper = productMapper;
    }

    @Override
    public List<ItemVO> getItemByOrderId(Integer orderId) {
        List<SItem> sItemList = itemMapper.selectAllByPrimaryKey(orderId, null);
        List<ItemVO> itemVOList = ColaBeanUtils.copyListProperties(sItemList, ItemVO::new, (sitem, itemvo) -> {
            itemvo.setName(productMapper.selectByPrimaryKey(sitem.getProductId()).getName());
        });
        return itemVOList;
    }
}
